const express = require('express');
const loginRoute = require('./routes/loginRoute');
const bookRoute = require('./routes/bookRoute');
const jwt = require('./utils/jwt'); // 导入 JWT 工具函数
const path = require('path');


const app = express();
app.use(express.json());
app.use(jwt.authenticateToken)

app.use('/', loginRoute);
app.use('/', bookRoute);

//处理静态文件
app.use('/static',express.static('./static'));
// 处理根路径请求
app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, 'static', 'main.html'));
})
// 处理favicon.ico请求
app.get('/favicon.ico', (req, res) => {
  res.sendFile(path.join(__dirname, 'static', 'test.ico'));
})

app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).json({ status:500,msg: '服务器错误' });
});

const port = 80;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
